package com.etocrm.saas.lib.base.common.obj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResponseVo<T> extends BaseVo {

    private PageVo page;

    private List<T> records;


    /**
     * 将mybatis-plus的Page对象转换为PageResponseVo对象
     *
     * @return
     */
    public PageResponseVo<T> buildPageResponseVo(IPage<T> page) {
        PageResponseVo<T> pageResponseVo = new PageResponseVo<>();
        pageResponseVo.setRecords(page.getRecords());

        PageVo pageVo = new PageVo();
        pageVo.setCurrentPage(page.getCurrent());
        pageVo.setPageSize(page.getSize());
        pageVo.setTotalPage(page.getPages());
        pageVo.setTotalCount(page.getTotal());

        pageResponseVo.setPage(pageVo);

        return pageResponseVo;
    }

}
